//
//  LBCCategoryHeadView.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LBCCategoryHeadView.h"

@interface LBCCategoryHeadView ()

@property (nonatomic, strong)UIImageView *imageOne;
@property (nonatomic, strong)UIImageView *imageTwo;
@property (nonatomic, strong)UIImageView *imageThree;
@property (nonatomic, strong)UIImageView *imageFour;
@property (nonatomic, strong)UIImageView *imageFive;

@end

@implementation LBCCategoryHeadView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageOne = [UIImageView new];
        [self addSubview:_imageOne];
        [_imageOne mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(10);
            make.bottom.mas_equalTo(-5);
            make.width.equalTo(_imageOne.mas_height);
            
        }];
        self.imageTwo = [UIImageView new];
        [self addSubview:_imageTwo];
        [_imageTwo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageOne.mas_top);
            make.left.equalTo(_imageOne.mas_right).offset(5);
            make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 30) / 4, (SCREEN_WIDTH - 30) / 4));
            
        }];
        
        self.imageThree = [UIImageView new];
        [self addSubview:_imageThree];
        [_imageThree mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageTwo.mas_top);
            make.left.equalTo(_imageTwo.mas_right).offset(5);
            make.right.mas_equalTo(-10);
            make.height.equalTo(_imageTwo.mas_width);
            
        }];
        
        self.imageFour = [UIImageView new];
        [self addSubview:_imageFour];
        [_imageFour mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageTwo.mas_bottom).offset(5);
            make.left.equalTo(_imageOne.mas_right).offset(5);
            make.bottom.equalTo(_imageOne.mas_bottom);
            make.width.equalTo(_imageTwo.mas_width);
            
        }];
        
        self.imageFive = [UIImageView new];
        [self addSubview:_imageFive];
        [_imageFive mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageThree.mas_bottom).offset(5);
            make.left.equalTo(_imageFour.mas_right).offset(5);
            make.right.equalTo(_imageThree.mas_right);
            make.bottom.equalTo(_imageOne.mas_bottom);
            
        }];
        
        _imageOne.tag = 1000;
        _imageTwo.tag = 1001;
        _imageThree.tag = 1002;
        _imageFour.tag = 1003;
        _imageFive.tag = 1004;
        _imageOne.userInteractionEnabled = YES;
        _imageTwo.userInteractionEnabled = YES;
        _imageThree.userInteractionEnabled = YES;
        _imageFour.userInteractionEnabled = YES;
        _imageFive.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tapTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tapThree = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tapFour = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tapFive = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [_imageOne addGestureRecognizer:tapOne];
        [_imageTwo addGestureRecognizer:tapTwo];
        [_imageThree addGestureRecognizer:tapThree];
        [_imageFour addGestureRecognizer:tapFour];
        [_imageFive addGestureRecognizer:tapFive];
        
    }
    return self;
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    [self.categorydelegate presentToListViewControllerTag:tap.view.tag];
}

-(void)setCategroyArr:(NSMutableArray *)categroyArr{
    _categroyArr = categroyArr;
    [_imageOne sd_setImageWithURL:[NSURL URLWithString:[_categroyArr[0] coverPath]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [_imageTwo sd_setImageWithURL:[NSURL URLWithString:[_categroyArr[1] coverPath]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [_imageThree sd_setImageWithURL:[NSURL URLWithString:[_categroyArr[2] coverPath]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [_imageFour sd_setImageWithURL:[NSURL URLWithString:[_categroyArr[3] coverPath]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [_imageFive sd_setImageWithURL:[NSURL URLWithString:[_categroyArr[4] coverPath]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
}



@end
